<template>
  <a-modal title-align="start" title="协商" :mask-closable="false" v-model:visible="showvisible" @cancel="showvisible = false" :width="600">
    <div>任务发起方/任务执行方，协商终止该任务，请确认？</div>
    <a-form :model="form" ref="formRef" auto-label-width>
      <a-form-item label="终止原因">
        <div>{{ $props.info.terminateReason }}</div>
      </a-form-item>
      <a-form-item label="备注理由">
        <div>{{ $props.info.terminateRemark }}</div>
      </a-form-item>
      <a-form-item label="是否同意">
        <a-radio-group v-model="form.accept">
          <a-radio :value="true">同意终止</a-radio>
          <a-radio :value="false">不同意终止</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="原因" v-if="form.accept == false">
        <a-textarea v-model="form.rejectReason" placeholder="请填写不同意原因" />
      </a-form-item>
    </a-form>
    <template #footer class="modal-footer">
      <a-button @click="showvisible = false">取消</a-button>
      <a-button type="primary" :loading="loading" @click="submit">确定</a-button>
    </template>
  </a-modal>
</template>

<script lang="ts" setup>
  import { defineComponent, ref, computed } from 'vue'
  import { negotiateTask } from '@/api/task'
  import { Message } from '@arco-design/web-vue'
  let props = defineProps(['modelValue', 'type', 'info'])
  let emits = defineEmits(['save', 'update:modelValue'])
  let showvisible = computed({
    get() {
      return props.modelValue
    },
    set(val) {
      emits('update:modelValue', val)
    },
  })
  const formRef = ref()
  let form: any = ref({})
  let loading = ref(false)
  const submit = async () => {
    const valid = await formRef.value.validate()
    if (valid) return
    let params = {
      ...form.value,
      idList: [props.info.id],
    }

    try {
      loading.value = true
      const res: any = await negotiateTask(params)
      if (res) {
        showvisible.value = false
        Message.success('操作成功')
        emits('save')
      }
    } catch (error) {}
    loading.value = false
  }
</script>

<style lang="less" scoped></style>
